<template>
  <div>
    <el-form ref="userForm" :model="user" :rules="rules" style="display: flex;justify-content: center;padding-top:200px">
      <el-card style="width: 400px">
        <div slot="header" class="clearfix">
          <span>后台登录</span>
        </div>
        <table style="margin:0 auto;height:auto;width:80%">
            <el-form-item  prop="account">
              <i class="el-icon-user" style="font-size:25px;padding-top:10px"></i>
              <el-input v-model="user.account" placeholder="请输入用户名" maxlength="20" style="width:250px"></el-input>
            </el-form-item>
            <el-form-item  prop="password">
              <i class="el-icon-lock" style="font-size:25px;padding-top:10px"></i>
              <el-input v-model="user.password" type="password" placeholder="请输入密码" 
              @keydown.enter.native="doLogin" maxlength="18" style="width:250px"></el-input>
            </el-form-item>
          <tr style="height:80px">
            <td colspan="2" style="margin-top:50px">
                <el-button style="width: 100px" type="primary" @click="doLogin('userForm')">登录</el-button>
            </td>
          </tr>
          
        </table>
      </el-card>
    </el-form>
  </div>
</template>
<script>
  export default {
    data() {
      return{
        user:{
          account:'',
          password:''
        },
        rules:{
          account: [
            { required: true, message: '请输入用户名', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ]
        }
      };
    },
    methods:{
      doLogin(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
        var data={
          username:this.user.account,
          password:this.user.password
        }
        console.log(data);
        const that=this;
            this.$axios({
                  url: '/Test/auditor/login.do',
                  method:'post',
                  headers:{'Content-Type': 'application/x-www-form-urlencoded'},
                  params:{
                    username:this.user.account,
                    password:this.user.password
                  }
               }).then(function(return_data)
              {
                if(return_data.data.code==1){
                  that.$alert("登录成功!");
                  that.$router.push({path:'/AuditAll'});
                }
                else{
                  that.$messgae.error("用户名或密码错误!")
                }
              },function(return_data)
              {
                alert(return_data)
              });
      }
    }
  }
</script>